package main

import (
	"fmt"
	"sync"
	"time"
)


type I_A  interface {
        Add(item string) 
	Done()
	Get() string

}


type empty struct{}
type t interface{}
type set map[t]empty

func (s set) has(item t) bool {
	_, exists := s[item]
	return exists
}

func (s set) insert(item t) {
	s[item] = empty{}
}

func (s set) delete(item t) {
	delete(s, item)
}

func (s set) len() int {
	return len(s)
}


type A  struct{
     Item  []t
     zhang      map[string]string      
     process    map[string]string 
     m    *sync.Mutex
     co   *sync.Cond

}

func (a *A)Add(item string){
        
	a.co.L.Lock()
	defer a.co.L.Unlock()
	a.zhang[item]="ok"
	a.Item=append(a.Item,item)
	fmt.Println("jiang", a.Item[0])
	
}


func (a *A)Get() t{
        a.co.L.Lock()
	defer a.co.L.Unlock()
	for len(a.Item) <= 0 {
                    a.co.Wait()

	}
	item := a.Item[0]
	
	a.Item = a.Item[1:]
	return item
}


func main(){

	a := A{Item:make([]t,0,10), zhang:make(map[string]string)}

	a.m = &sync.Mutex{}

	a.co = sync.NewCond(a.m)

        a.Add("jiang")

        for i:=0 ;i<10;i++{
        
	go func(in int){
                       fmt.Println(  a.Get() ,"index " ,in) 

	           }(i)
	}


       time.Sleep(time.Second*10)

        
}




